﻿// Decompiled with JetBrains decompiler
// Type: Netick.NetworkPlayerId
// Assembly: Netick, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 6726ECA1-C773-4CF7-8952-E81B30D93B52
// Assembly location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.dll
// XML documentation location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.xml

using System;

#nullable disable
namespace Netick;

/// <summary>
/// Represents a networked struct identifier for a <see cref="T:Netick.NetworkPlayer" />.
/// </summary>
[Serializable]
public struct NetworkPlayerId : IEquatable<NetworkPlayerId>
{
  private int _id;

  public int Id => this._id > 0 ? this._id - 1 : -1;

  public bool IsValid => this.Id >= 0;

  public NetworkPlayerId(int id) => this._id = NetworkPlayerId.Create(id)._id;

  public static NetworkPlayerId Invalid
  {
    get => new NetworkPlayerId() { _id = 0 };
  }

  internal static NetworkPlayerId Create(int id, PlayerData dat)
  {
    return new NetworkPlayerId()
    {
      _id = dat.Version <= 0 ? -1 : id + 1
    };
  }

  internal static NetworkPlayerId Create(int id)
  {
    return new NetworkPlayerId() { _id = id + 1 };
  }

  public static implicit operator int(NetworkPlayerId playerId) => playerId.Id;

  public bool Equals(NetworkPlayerId other) => this._id == other._id;

  public override bool Equals(object obj) => obj is NetworkPlayerId other && this.Equals(other);

  public override int GetHashCode() => this._id;

  public static bool operator ==(NetworkPlayerId left, NetworkPlayerId right) => left.Equals(right);

  public static bool operator !=(NetworkPlayerId left, NetworkPlayerId right) => !(left == right);

  public override string ToString() => $"{this.Id}";
}
